<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<div id="propertyParamDiv"  style="padding:20px;">
		<table cellpadding="5" class="property hide" >
			    
		</table>
</div>
<div style="text-align: center;">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="UpdatePropertyParam()">提交修改</a>
</div>
<script type="text/javascript">
//生成属性表
$.post("propertyParam/getPropertyInfoById",{id:$('#goodsData').datagrid('getSelected').gId},function(data){
	  if(data.status == 200 && data.data){
		 var paramData = JSON.parse(data.data.gppParamData);
		 
		 for(var i in paramData){
			 var html = '<tr><td><span>'+ paramData[i].property+'</span>: ';
			 var propertyParams=paramData[i].params.toString().split(",");
			 var tempLen=propertyParams.length;
				 for(var i=0;i<tempLen;i++){
					 html+='<input value=' +propertyParams[i]+'  style=\"width: 150px;\" class=\"inputId\" name=\"param\"/>&nbsp;';
				 } 
				html+=' <button class="addButton" type="button">添加</button></td></tr>';
		
			 $("#propertyParamDiv .property").append($(html));
		 }
		 $(".addButton").click(function(){
		    	 var htm="<input  style=\"width: 150px;\" class=\"inputId\" name=\"param\"/>&nbsp;&nbsp;&nbsp;";
		    	$(htm).insertBefore(this); 
		    	$(".inputId").textbox({
					disabled:false
				}); 
		    });
		 
	  }else{
		  $.messager.alert('错误',data.data,'info');
	  }
	  $(".inputId").textbox({
			disabled:false
		}); 
  });
  function UpdatePropertyParam(){
			//属性数据获取
			var propertys = [];
			$("#propertyParamDiv .property tr").each(function(i,e){
				
				  var property= $(e).find("span").eq(0).text();
				var val="";
				 var valsInput=$(e).find("input");
				 var j=valsInput.length;
				for(var i = 2;i<j;i=i+3){
					val+=valsInput.eq(i).val()+",";
				}
				val=val.substring(0,val.lastIndexOf(","));
				propertys.push({
					"property" : property,
					"params": val
				});
			});
			
			//alert(JSON.stringify(propertys));
			
			$.post("propertyParam/updatePropertyParamInfoById",{id:$('#goodsData').datagrid('getSelected').gId,property:JSON.stringify(propertys)},function(data){
				if(data.status == 200){
					$.messager.show({
						title:'成功提示',
						msg:'商品属性数据修改成功',
						timeout:5000,
						showType:'slide'
					});
				}else{
					$.messager.alert('提示',data.data,'info');
				}
			});
  }
</script>